#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){

  int fd = open("test.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
  if(fd < 0) exit(1);
  dup2(fd, 1);

  //使用系统调用接口
  printf("printf\n");
  fprintf(stdout, "fprintf\n");
  char* str = (char*)"fputs\n";
  fputs(str, stdout);

  //系统调用
  char* msg = (char*)"writr\n"; 
  write(1, msg, strlen(msg));

  fork();
  return 0;
}


